/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

/**
 * handle exception happen. Will log all exception to file
 *
 * @author lhaquang
 */
public class ExceptionHandle {

    private static final Object syncObject = new Object();     //use to wirte file
    private static String errorFile = "logs/error.txt";
    private static PrintWriter pw = null;

    public static void logException(Exception ex) {
        synchronized (syncObject) {
            if (pw == null) {
                try {
                    pw = new PrintWriter(new File(errorFile));
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            ex.printStackTrace(pw);
            pw.flush();
        }
    }
}
